/**
 * api/index
 */

const lodash = require('lodash');

module.exports = function(app) {
    const router = app.router;

    /**
     * @apiVersion 1.0.0
     * @apiGroup Home
     * @api {get} / 获取所有接口列表
     * @apiSuccessExample Success
     * {
     *     "templets_url": "/templets"
     * }
     *
     * @apiSampleRequest
     */
    router.get('/', function * () {
        let routes = {
        };

        let routerStackMap = {};
        lodash.forEach(router.stack, layer => {
            routerStackMap[layer.path] = layer;
        });

        // 只显示已支持的接口
        lodash.forEach(routes, (uri, key) => {
            if(!routerStackMap[uri]) {
                delete routes[key];
            }
        });

        this.body = routes;
    });
};
